import http from '@/utils/http'
import type * as User from './types'
import type { MenuItem } from '@/api'

enum API {
  LOGIN_URL = '/mock/user/login',
  LOGOUT_URL = '/mock/user/logout',
  USER_INFO_URL = '/mock/user/getUserInfo',
  ROUTE_URL = `/mock/user/routes`,
}

/**
 * 登录
 * @param data
 */
export const login = (data: { username: string; password: string }) => {
  return http.post<User.LoginRes>(API.LOGIN_URL, data)
}

/**
 * 退出登录
 */
export const logout = () => {
  return http.post(API.LOGOUT_URL)
}

/**
 * 获取用户信息
 */
export const getUserInfo = () => {
  return http.get<User.UserInfo>(API.USER_INFO_URL)
}

/** @desc 获取用户路由信息 */
export const getUserAsyncRoutes = () => {
  return http.get<MenuItem[]>(API.ROUTE_URL)
}
